home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / BSP Tree 1.2 / Sources / Graphics / source / cube.cp < prev    next >
Encoding:
Text File  |  1995-03-26  |  1.9 KB  |  40 lines  |  [TEXT/MMCC]

  1. //------------------------------------------------------------------------------
  2. //    File:                    cube.cp
  3. //    Date:                    11/02/94
  4. //    Author:                Bretton Wade
  5. //
  6. //    Description:    this file contains the function for cube generation
  7. //
  8. //------------------------------------------------------------------------------
  9.  
  10. #include "cube.h"
  11.  
  12. //------------------------------------------------------------------------------
  13. //    generate a cube
  14. //------------------------------------------------------------------------------
  15. listptr    Cube (matrix_3d transformation)                                                                                    //    compute a cube given a transformation
  16. {                                                                                                                                                                //    begin
  17.     point_3d        cube_points[8];                                                                                                        //    eight vertices
  18.     //    compute the vertices
  19.     cube_points[0] = point_3d (R( 1.0), R( 1.0), R( 1.0)) * transformation;
  20.     cube_points[1] = point_3d (R(-1.0), R( 1.0), R( 1.0)) * transformation;
  21.     cube_points[2] = point_3d (R(-1.0), R(-1.0), R( 1.0)) * transformation;
  22.     cube_points[3] = point_3d (R( 1.0), R(-1.0), R( 1.0)) * transformation;
  23.     cube_points[4] = point_3d (R( 1.0), R( 1.0), R(-1.0)) * transformation;
  24.     cube_points[5] = point_3d (R(-1.0), R( 1.0), R(-1.0)) * transformation;
  25.     cube_points[6] = point_3d (R(-1.0), R(-1.0), R(-1.0)) * transformation;
  26.     cube_points[7] = point_3d (R( 1.0), R(-1.0), R(-1.0)) * transformation;
  27.     //    now compute the polygons
  28.     listptr    cube_polys;
  29.     cube_polys->AddToList (polyptr (cube_points, 4, 0, 1, 2, 3));
  30.     cube_polys->AddToList (polyptr (cube_points, 4, 7, 6, 5, 4));
  31.     cube_polys->AddToList (polyptr (cube_points, 4, 0, 3, 7, 4));
  32.     cube_polys->AddToList (polyptr (cube_points, 4, 0, 4, 5, 1));
  33.     cube_polys->AddToList (polyptr (cube_points, 4, 5, 6, 2, 1));
  34.     cube_polys->AddToList (polyptr (cube_points, 4, 3, 2, 6, 7));
  35.     //    return the result
  36.     return cube_polys;
  37. }                                                                                                                                                                //    end
  38.  
  39. //------------------------------------------------------------------------------
  40.